﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TM.Data.Contracts;
using TM.Model;

namespace TM.Data
{
    public class TMUnitofWork : IUnitOfWork, IDisposable
    {

        public TMUnitofWork(IIoCParams ioCParams)
        {
            Project = (IProjectRepository)RepositoryFactories.GetRepository<Project>(ioCParams);
            Task = (IProjectTaskRepository)RepositoryFactories.GetRepository<ProjectTask>(ioCParams);
            Evident = (IEvidentRepository)RepositoryFactories.GetRepository<Evident>(ioCParams);
            Resource = (IResourceRepository)RepositoryFactories.GetRepository<DMNhanVien>(ioCParams);
            Scope = (IScopeRepository)RepositoryFactories.GetRepository<Scope>(ioCParams);
            Status = (ITaskStatusRepository)RepositoryFactories.GetRepository<TaskStatus>(ioCParams);
        }

        #region Implementation of IUnitOfWork

        public IEvidentRepository Evident { get; private set; }
        public IProjectRepository Project { get; private set; }
        public IProjectTaskRepository Task { get; private set; }
        public IResourceRepository Resource { get; private set; }
        public IScopeRepository Scope { get; private set; }
        public ITaskStatusRepository Status { get; private set; }

        #endregion

        #region Implementation of IDisposable

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        public void Dispose()
        {
            GC.Collect();
            GC.SuppressFinalize(this);
        }

        #endregion
    }
}
